package com.excel;

import com.alibaba.excel.EasyExcel;
import com.alibaba.excel.EasyExcelFactory;
import com.alibaba.excel.ExcelWriter;
import com.alibaba.excel.annotation.ExcelProperty;
import com.alibaba.excel.metadata.Sheet;
import com.alibaba.excel.metadata.Table;
import com.alibaba.fastjson.JSONArray;
import com.excel.config.CustomCellWriteHandler;
import com.excel.domian.DemoData;
import org.apache.poi.ss.formula.functions.T;


import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.lang.reflect.Field;
import java.util.*;
import java.util.Map.Entry;

/**
 * @author Xiongx
 * @version 1.0
 * @date 2021/4/16 11:18
 * @since JDK 1.8
 */
public class Test2 {

    public static void main(String[] args){
        List<Map<String, Object>> object = new ArrayList<>();
        for (int i = 0; i < 1000; i++) {
            Map<String, Object> objectMap=new HashMap<>();
            objectMap.put("name","姓名"+i);
            objectMap.put("age","年龄"+i);
            objectMap.put("sex","性别"+i);
            objectMap.put("address","住址"+i);
            objectMap.put("note","备注"+i);
            object.add(objectMap);
        }
        Map<String, String> o=new HashMap<>();
        o.put("age","年龄");
     //   formartExcelHead("C:\\Users\\xiong\\Desktop\\test2131.xlsx",object,o);
    }

    public static void Test1(){
        List<DemoData> demoData=new ArrayList<>();
        for (int i = 0; i < 10; i++) {
            DemoData demoData1=new DemoData();
            demoData1.setDate(new Date());
            demoData1.setDoubleData(10.00+i);
            demoData1.setString("数据"+i);
            demoData1.setIgnore("shuju"+i);
            demoData.add(demoData1);
        }

    }



    public static void simpleWrite(){
        // 文件输出位置
        String outPath = "C:\\Users\\xiong\\Desktop\\test11.xlsx";
        try {
            // 所有行的集合
            List<List<Object>> list = new ArrayList<>();

            for (int i = 1; i <= 10; i++) {
                // 第 n 行的数据
                List<Object> row = new ArrayList<Object>();
                row.add("第" + i + "单元格");
                row.add("第" + i + "单元格11");
                row.add("dddddd");
                list.add(row);
            }

            ExcelWriter excelWriter = EasyExcelFactory.getWriter(new FileOutputStream(outPath));
            // 表单
            Sheet sheet = new Sheet(1,0);
            sheet.setSheetName("第一个Sheet");
            // 创建一个表格
            Table table = new Table(1);
            // 动态添加 表头 headList --> 所有表头行集合
            List<List<String>> headList = new ArrayList<List<String>>();
            // 第 n 行 的表头
            List<String> headTitle0 = new ArrayList<String>();
            List<String> headTitle1 = new ArrayList<String>();
            List<String> headTitle2 = new ArrayList<String>();
            headTitle0.add("最顶部-1");
            headTitle0.add("标题1");
            headTitle1.add("最顶部-1");
            headTitle1.add("标题2");
            headTitle2.add("最顶部-1");
            headTitle2.add("标题3");

            headList.add(headTitle0);
            headList.add(headTitle1);
            headList.add(headTitle2);
            table.setHead(headList);

            excelWriter.write1(list,sheet,table);
            // 记得 释放资源
            excelWriter.finish();
            System.out.println("ok");
        } catch (FileNotFoundException e) {
            e.printStackTrace();
        }

    }
}
